package com.BMS.ServiceImpl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.BMS.DAOImpl.BookDaoImpl;
import com.BMS.DAOImpl.BorrowDaoImpl;
import com.BMS.DAOImpl.GiveBackDaoImpl;
import com.BMS.Service.BookService;
import com.BMS.entity.Book;
import com.BMS.entity.Borrow;
import com.BMS.entity.GiveBack;

/**
 * 图书实体类业务层实现类
 * 
 * @author lenovo
 *
 */
@Transactional
@Service("BookService")
public class BookServiceImpl implements BookService {

	@Autowired
	public BookDaoImpl bookDao;

	@Autowired
	public BorrowDaoImpl borrowDao;

	@Autowired
	public GiveBackDaoImpl giveBackDao;

	// 图书类
	// add
	public void addBook(Book book, String manager_id, Date takeOn_date) {
		bookDao.addBook(book, manager_id, takeOn_date);
	}

	// delete
	public void deleteBookById(String book_id) {
		bookDao.deleteBookById(book_id);
	}

	// takeOff
	// @param book_id, manager_id, takeOff_date
	public void takeOffBook(String book_id, String manager_id, Date takeOff_date) {
		bookDao.takeOffBook(book_id, manager_id, takeOff_date);
	}

	// find
	public Book findBookById(String book_id) {
		return bookDao.findBookById(book_id);
	}

	public List<Book> findAllBooks(int offset, int length, String orderBy) {
		return bookDao.findAllBooks(offset, length, orderBy);
	}

	// update
	public void updateBook(Book book) {
		bookDao.updateBook(book);
	}

	// getPageCount
	public long getPageCount() {
		return bookDao.getPageCount();
	}

	// 图书借阅类
	@Override
	public void addBorrow(Borrow borrow) {
		borrowDao.addBorrow(borrow);
	}

	@Override
	public void deleteBorrow(int borrow_id) {
		borrowDao.deleteBorrowById(borrow_id);
	}

	@Override
	public Borrow findBorrowById(int borrow_id) {
		return borrowDao.findBorrowById(borrow_id);
	}

	public Borrow findBorrowByBookId(String book_id) {
		return borrowDao.findBorrowByBookId(book_id);
	}

	@Override
	public void updateBorrow(Borrow borrow) {
		borrowDao.updateBorrow(borrow);
	}

	// get the status of book to borrow
	@Override
	public boolean isBorrowable(String book_id) {
		return borrowDao.isBorrowable(book_id);
	}

	// 图书归还类
	@Override
	public void addGiveBack(GiveBack giveBack) {
		giveBackDao.addGiveBack(giveBack);
	}

	@Override
	public void deleteGiveBack(int giveBack_id) {
		giveBackDao.deleteGiveBackById(giveBack_id);
	}

	@Override
	public Borrow findGiveBackById(int giveBack_id) {
		return borrowDao.findBorrowById(giveBack_id);
	}

	@Override
	public void updateGiveBack(GiveBack giveBack) {
		giveBackDao.updateGiveBack(giveBack);
	}

}
